package com.aeks.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aeks.user.AboutUser;

public class SetParamServlet extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		
		boolean isSuccess = false;
		String action = request.getParameter("action");
		if (action != null && action.equals("setparam")) {
			String limitValue = request.getParameter("limitValue");
			String titleValue = request.getParameter("titleValue");
			String briefValue = request.getParameter("briefValue");
			String keyValue = request.getParameter("keyValue");
			String textValue = request.getParameter("textValue");
			HttpSession session = request.getSession();
			String username = (String)session.getAttribute("username");
			isSuccess = AboutUser.setParam(limitValue, titleValue, briefValue, keyValue, textValue, username);
		}
		
		if(isSuccess) {
			out.println("<script language='javascript'>");
			out.println("alert('修改成功！');");
			out.println("window.location.href='main.jsp'");
			out.println("</script>");
		} else {
			out.println("<script language='javascript'>");
			out.println("alert('修改失败，请重新修改!');");
			out.println("window.location.href='main.jsp'");
			out.println("</script>");
		}
		out.flush();
		out.close();
	}

}
